import { Prisma } from '@prisma/client';
import { BaseQueryDto } from './base.dto';
import { IsDefined, IsNotEmpty, Max, Min, ValidateIf } from 'class-validator';
import { Transform } from 'class-transformer';

export class MarketListDto extends BaseQueryDto<Prisma.TokenWhereUniqueInput> {
  type?: number;
  albumId?: number;
  minPrice?: number;
  maxPrice?: number;
  title?: string;
}

export class MarketSalesDto extends BaseQueryDto<Prisma.TokenWhereUniqueInput> {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  type?: number;
}

export class MarketOrderDto {
  @IsDefined({ message: '资产ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @ValidateIf((o) => !!o.tokenId)
  @Transform(({ value }) => Number(value))
  tokenId?: number;

  @ValidateIf((o) => !!o.num)
  @Transform(({ value }) => Number(value))
  @Min(1, { message: '数量不能小于1' })
  @Max(30, { message: '数量不能大于30' })
  num?: number;

  @ValidateIf((o) => !!o.price)
  @Transform(({ value }) => Number(value))
  @Min(1, { message: '限价不能小于1' })
  @Max(20000, { message: '限价不能大于20000' })
  price?: number;
}

export class MarketDownDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class MarketBatchDownDto {
  @IsDefined({ message: '未选择对象' })
  ids: number[];
}

export class MarketBatchUpDto {
  @IsDefined({ message: '未选择对象' })
  ids: number[];

  @IsDefined({ message: '未输入金额' })
  @Transform(({ value }) => Number(value))
  @Min(1, { message: '限价不能小于1' })
  @Max(20000, { message: '限价不能大于20000' })
  price: number;
}
